home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Commodore Free 40
/
Commodore_Free_Issue_40_2010_Commodore_Computer_Club.d64
/
c 16
< prev
next >
Wrap
Text File
|
2023-02-26
|
11KB
|
449 lines
*************************************
COMMODORE FREE BASIC PROGRAMMING
CHALLENGE
Adapted C16 Version
By John Fielden
*************************************
Listing of: asteroid16.prg
10 REM *ASTEROIDS, NIGEL PARKER*
(C64)
20 REM *C16 VERSION, JOHN FIELDEN*
30 DIMHI(15):DIMHI$(15)
40 HI(0)=90:HI$(0)="STAR
MAN":HI(1)=50:HI$(1)="SUPER STAR"
50 HI(2)=40:HI$(2)="STAR
MAN":HI(3)=30:HI$(3)="SUPER STAR"
60 F=100 :JF=0
70 A=0:B=A:C=A:I=A:S=A:F=40:A$=""
80
PRINTCHR$(147);:POKE65305,0:POKE65301
,0:POKE1339,113
90 REM PRINTCHR$(5)
100 FORI=0TO23:PRINT:NEXTI
110
B=1504:C=20:M=16:SC=3072:CO=2048:WI=4
0:HG=25
120
B=SC+WI*INT(HG/2):C=INT(WI/2):BS=SC+W
I*(HG-1)
130
A=INT(40*RND(1)):IFRND(0)<.333THENA=0
140 Z=INT(40*RND(1))
150 IFA>0THENPOKE4012+A,46 :REM *DOT*
160
IFRND(1)>.1THENP=INT(RND(1)*40):POKE4
012+Z,42 :REM *STAR*
170 GETA$ :REM(OWN LINE, MORE
READABLE)
180 IFC<1THEN190:ELSEIFA$="Z"
THENPOKEB+C,32:C=C-1
190 IFC>38THEN200:ELSEIFA$="X"
THENPOKEB+C,32:C=C+1
200 POKEB+C,32 :REM *[SPACE]*
210 PRINT:F=F-1:IFF<1THEN270
220 IFPEEK(B+C)=42 THENJF=1:GOTO270
230 IFPEEK(B+C)=46 THENGOSUB350
240 POKEB+C,22 :REM * V *
250 S=S+1
260 GOTO130
270 PRINTCHR$(147);
280 PRINT"SORRY! ";
290 IFJF=1THEN PRINT"YOU HIT AN
ASTEROID":ELSEPRINT" YOU RAN OUT OF
FUEL!"
300 PRINT"YOU SCORED ";S;" POINTS"
310 PRINT
320 IFJF=1THEN PRINT" AND HAD ";F;"
FUEL LEFT IN TANK"
330 PRINT
340 FORJA=0TO600:GETA$:NEXTJA:
GOTO360
350
FORI=0TO16:POKE65305,I:NEXTI:F=F+10:R
ETURN
360 REM *ELITE PILOTS*
370 PRINT
380 FORJ=0TO10
390 IF S> HI(J) AND J<10THEN420
400 NEXTJ
410 GOTO500
420 PRINT"{SHIFT-+}down{SHIFT--} ELITE TABLE OF
PILOTS"
430 INPUT"{SHIFT-+}down{SHIFT--} ENTER NAME ";N$
440 N$=LEFT$(N$,15)
450 FORX=JTO12
460 DV=HI(X):DV$=HI$(X)
470 HI(X)=S:HI$(X)=N$
480 S=DV:N$=DV$
490 NEXTX
500 REM *PILOT TABLE*
510 PRINT"{SHIFT-+}clr{SHIFT--} ASTEROID GAME, BY
NIGEL PARKER."
520 PRINT" C16 CONVERSION, JOHN
FIELDEN (2010)"
530 PRINT" WWW.COMMODOREFREE.COM
ONLINE MAGAZINE!"
540 PRINT
550 PRINT" ELITE PILOTS"
560 PRINT"{SHIFT-+}down{SHIFT--}"
570 PRINT" NAME SCORE"
580 PRINT
590 FORT=0TO9:PRINTT+1;
600
IFHI(T)=0THENHI$(T)="COMMODOREFREE"
610 PRINTHI$(T);"
":PRINT"{SHIFT-+}up{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}rig
ht{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right
{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}
right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}ri
ght{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}";HI(T)
620 NEXTT
630 PRINT"{SHIFT-+}down{SHIFT--} ANOTHER Y/N?"
640 GETKEYA$
650 IFA$<>"N"THEN60
10 & 20 Always good to mark where it
came from, and what it is.
Though we're learning REM statements
slow the program down. These won't
as they only get read once, And
aren't in any repeated use loops
etc. So, the only question is the
excess memory total they take up.
Once you have the program in memory,
type in this line:
PRINTFRE(X)
After playing the game a few times,
upon exit. I got the answer: 58602
This is free memory in bytes. It is
Yape, the plus4 emulator. The c16
will have a smaller answer.
Type, followed by return key press.
1
2
then retype printfre(x) line, or go
up to it. space out the answer
beneath it and go to it, then press
return key. The answer I get is
59110. As I have no ability in maths
I typed.
?59110-58602 <return>
Gave the answer 508 followed by
Ready.
Err, actually no! I didn't think
two little REM statements would take
up so much room. There are several
more statements in the listing,
though I did keep these to a minimum
for sake of speed. While on the
subject of speed and saving memory;
I've already renumbered the program
lines to increment by 1. and lost a
grand total of 9 bytes! It seems
the computer prefers to increment
lines by 10.
3 HI controls the score, while HI$
is name that goes with it.
I put this into 15, so screen
permitting, the high score table can
go up to 14 (from 0). The remainder
is for calculation purposes.
Reducing these to 12 doesn't seem to
alter the free memory space. And
when I started adding the high score
table, though I knew it took only
three or four commands to sort.
Which three were correct, and the
right order was driving me up the
wall. More on that later.
Suffice to say I used a makeshift
complex system of two tables, adding
the new high score, and copying it
over before putting it back again
from that point. Something still on
file in case any-one is interested
in a sort of 'long division' version
of the sort technique.
4 & 5 I put these in for debugging
purposes, and are all but completely
unnecessary, apart from aesthetics
quality. They give new pilots
something EASY to aim at, at the
start.
6 Nothing is in the c64 version
yet. This is also added, as the
game has been changed slightly. The
reason for this line is because it
is extremely good programming to
always set the variables, and even
constants at the start of the
program, and obviously at the value
they start at. For instance, it is
no good thinking; this variable
starts at 0 so I don't need to set
it. ...
What if the program is modified
later. A good point is the high
score table, which allows the user
to play another game. You can't
just clear memory because you need
the recorded scores in tact. JF
determines whether an asteroid has
been hit, or whether the pilot
wasn't able to refuel in time. As
now there are two ways to meet a
demise.
7. You will know this from line 10
of the original c64 version. Added
is F=40.
8. the chr$ code is the same. The
POKEs have different register
values. See orig. 90
9 ...has vanished. It took awhile,
counting in values of 16 from the
first grey point for POKE1339, 113
is the best white colour. Though
things aren't always white in space.
I had a chr$(5) for code white to
overrule the prior grey. But now it
isn't needed.
10 as line 100 of orig.
11 has changed somewhat since line
110 of orig. b and c are on the
next line. (This makes them defunct
on line 7. Neither is A needed as
it is there on line 13. delete
them, change the =A to =0. then
check fre(x)...I got 59140 with
increments of ten!)
12 & 13 & 14 A lot of complicated
calculations, best left for a
professor of mathematics, which I am
not. But SC refers to the character
set in POKE codes. It shouldn't be
SC really as this is reserved for
Scores usually. But it is part of a
cheat sheet I was given, when my
original attempt at converting the
c64 code came back without drawing
the ship, or referring to it at all.
Just an endless scroll of asteroids
and fuel dumps. So I've kept this
as is.
15 p4012 is a place on screen, plus
a determines where on that line the
dot, i.e. "fuel dump" will go.
16 Put a star along the line. Not
necessarily in a different place,
but will take precedence over the
dot if writing over it.
17 look for a key press, but
continue on your way; reading the
following lines. We can take the
REM statement out as it says, the
geta$ statement is better on its
own, and the REM is counter
productive to this end. Changed
from the orig. line 150.
18 as rest of 150 in orig. move the
ship left upon keypess "Z"
19 as orig. 160, except originally
this was "M". I changed it to "X"
so that it is easier to navigate
with one hand. The other was
dedicated to eating cola bottles
throughout testing! (Ahh! that
Quinine hit, yum!!!). moves ship to
right on apt. key press. change if
you wish.
20 put a space in last ship
position. As orig. 170
21 line feed, as 175 :F is Fuel. As
we go on our way, fuel is used. If
ship runs out it becomes lost in
space. Let's change "Super Star" at
line 3 to "Will Robinson", and while
we're at it line 5 to "Captain Kirk"
or vice-versa. Aye commander, sir!
EDITOR Hmmmm that Quinine hit is
having strange effects on you
22 Hit an asteroid, again goto27 to
end game. "It's worse than that
he's dead Jim!"- orig. 180
23 more fuel. As orig. 190
24 place ship. As 195. Another REM
can be edited out.
25 Increase score as much as fuel
decreases. 1 per "scroll".
26 As orig. line 300. All the
scroll did was push the characters
printed one line up, though the ship
is cleverly replaced, so it doesn't
scroll up, but appears to stay where
it is. (though it would be more
convincing if we could remove the
flashing on and off all the time.)
We go back for a new value of A.
And start the whole process again
from there.
27 to 33 self explanatory Print
statements,
34 Any extra key presses after the
crash became nullified with this
statement, while the user is given
chance to take in what has just
happened.
35 A subroutine, adding 10 units of
fuel, upon hitting a dot.
36 Only necessary while you
familiarise yourself with program.
Then you may delete this line,
renumber1,1,1 and see if it runs
faster.
37 Add a line.
38 start a new count
39 if pilots score is greater than
the one on the hi-table, at the
point of where we are, and within
range of shown table THEN leave this
count.
40 if not, see if next one is.
41 if we haven't skipped this line,
it means we're not good enough this
score to go on the elite table. So
skip to the screen print of the
pre-existing table.
42 inform user, your in!
43 get their name
44 make sure it isn't a ridiculous
length that won't fit and throw the
whole thing up in the air.
45 continue last count from where it
left off
46 make dummy variable for currently
positioned table score
47 put new score in table at this
same position.
48 place Dummy Variable as though it
were score, ready to be put in at
the next increment.
49 increment by 1. i.e. add 1 to x,
and go back to 45 to pass through
loop again.
50 actual table screen print, title.
51 to 53 as it says,
acknowledgements.
54 skip a line
55 spaces in relevant place haven't
been listed. (11)
56 could blank this line, and put
cursor down in next line for same
effect.
57 more spaces missed. After NAME
(17)
58 miss a line for aesthetics.
59 start a new count, print the
count as placement, adding 1 because
who was ever the nought best at
anything? That's why I like
computers, their in a world of their
own! The semi colon ";" (or "dot
uh, comma!" as Dad would call it
constantly when we typed in Star
Trader from Melbourne House' Games
Book, tells the computer to keep the
cursor there, on that line.
60 If score at current count hasn't
been occupied then advertise this
excellent magazine!
61 put the score in the appropriate
place on the same line as current
count.
62 get info. For next count.
63 wait for next challenge, end if
told no.
64 wait for key to be pressed.
65 if not N, assume another game is
requested. if it is No, game comes
to natural END, without need for
statement because there is no sub
routine (yet) following it.
NOTE: I've included listing with
increments of 10, so you can easily
alter the program accordingly, and
perhaps make your own changes. The
conversion is easy, put a 0 on the
end of each line number so 1 becomes
10 etc
=====================================